import 'package:data/repository/banner/banner_repository.dart';
import 'package:data/response/banner_response.dart';
import 'package:domain/usecases/banner_use_case.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

class MockRepo extends Mock implements BannerRepository {}

void main() {
  group('banner use case testes', () {
    late MockRepo repo;
    late BannerUseCase useCase;

    setUp(() {
      repo = MockRepo();
      useCase = BannerUseCaseImpl(repo: repo);
    });

    tearDown(() {
      reset(repo);
    });

    test('should has response', () async {
      final imagePath = '3';
      final desc = '33';
      final title = 'sss';
      final id = 2;
      final testResponse = BannerResponse(
        id: id,
        title: title,
        desc: desc,
        imagePath: imagePath,
      );
      when(() => repo.fetchBanners()).thenAnswer((_) async => [testResponse]);
      final result = await useCase.fetchBanners();
      expect(result.isNotEmpty, true);
      expect(result.length, 1);
      expect(result[0].id, id.toString());
      expect(result[0].title, title);
      expect(result[0].desc, desc);
      expect(result[0].imageUrl, imagePath);
    });

    test('should has no response when repo returns no nothing', () async {
      when(() => repo.fetchBanners()).thenAnswer((_) async => []);
      final result = await useCase.fetchBanners();
      expect(result.isEmpty, true);
    });

    test('should has no response when exception occurs', () async {
      when(() => repo.fetchBanners()).thenThrow(Exception());
      final result = await useCase.fetchBanners();
      expect(result.isEmpty, true);
    });
  });
}
